package com.lagou.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lagou.feign.GoodsFeign;
import com.lagou.mapper.OrderMapper;
import com.lagou.pojo.Goods;
import com.lagou.pojo.Order;
import com.lagou.service.OrderService;
import feign.Feign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 */
@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

    //根据订单id查询订单
    @Override
    public Order findOrderById(Integer id) {
        Order order = orderMapper.selectById(id);
        return order;
    }

    //分页查询
    @Override
    public Map<List, Integer> selectOrderByPage(Integer page, String createTimemin, String createTimemax, String status) {
        QueryWrapper<Order> objectQueryWrapper = new QueryWrapper<>();
        objectQueryWrapper
                .between("create_time",createTimemin,createTimemax)
                .eq("status",status);


        Page orderPage = new Page(page,10);

        IPage<Order> iPage = orderMapper.selectMapsPage(orderPage,objectQueryWrapper);
        System.out.println("总条数：" + iPage.getTotal());
        System.out.println("总页数：" + iPage.getPages());

        System.out.println("当前页的分页数据：" + iPage.getRecords());
        Map<List, Integer> map = new HashMap<>();
        map.put(iPage.getRecords(), iPage.getRecords().size());
        return map;

    }


    @Autowired
    private GoodsFeign goodsFeign;
    //根据订单id查询商品列表
    @Override
    public Goods selectGoodsListById(Integer id) {
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        Order order = orderMapper.selectById(id);
        System.out.println(order.getGid());
        Goods goodsById = goodsFeign.findGoodsById((int) order.getGid());


        return goodsById;
    }
}
